//
//  PoetryViewController.m
//  FuncFanc
//
//  Created by hubing on 2018/8/21.
//  Copyright © 2018年 huhu. All rights reserved.
//

#import "PoetryViewController.h"
#import "PoeCell.h"

@interface PoetryViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic,strong) UICollectionView *collecView;
@property (nonatomic,strong) UICollectionViewFlowLayout *flow;
@property (nonatomic,strong) Poem *poe;

@end

@implementation PoetryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    _poe = [[Poem alloc]init];
    
    _poe.title = @"对酒五首其一";
    
    _poe.paragraphs = @[@"巧拙贤愚相是非，何如一醉尽忘机。",
                       @"君知天地中宽窄，雕鹗鸾皇各自飞。",
                       @"蜗牛角上争何事，石火光中寄此身。",
                       @"随富随贫且欢乐，不开口笑是痴人。",
                       @"丹砂见火去无迹，白发泥人来不休。",
                       @"赖有酒仙相暖热，松乔醉即到前头。",
                       @"百岁无多时壮健，一春能几日晴明。",
                       @"相逢且莫推辞醉，听唱阳关第四声。",
                       @"昨日低眉问疾来，今朝收泪吊人回。",
                       @"眼前流例君看取，且遣琵琶送一杯。"];
    _poe.authorName = @"杜甫";
    
    _flow = [[UICollectionViewFlowLayout alloc]init];
    _flow.headerReferenceSize = CGSizeMake(ScreenWidth, 0);
    _flow.minimumLineSpacing = 0;
    _flow.minimumInteritemSpacing = 0;
    _collecView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:_flow];
    _collecView.delegate = self;
    _collecView.dataSource = self;
    _collecView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_collecView];
    [_collecView registerClass:[PoeCell class] forCellWithReuseIdentifier:@"cell"];
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(ScreenWidth, ScreenWidth);
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 1;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    PoeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[PoeCell alloc]init];
    }
    [cell configPoeCellWithData:_poe];
    return cell;
}


@end
